import * as THREE from "three"
import CameraData from "../data/CameraData"
import SettingsData from "../data/SettingsData"
import ViewmodeData from "../data/ViewmodeData"
import EngineContext from "../EngineContext"
import InputIniModule from "../module/InputIniModule"
import Module from "../module/Module"
import WebGLRendererModule from "../module/WebGLRendererModule"
import SymbolList from "../SymbolList"
import ExtObjRender from "./ExtObjRender"
import ExtObjViewData from "./ExtObjViewData"
import "./ExtTHREE"
export default class ExtObjModule extends Module {
  engine: EngineContext
  touchDevice: boolean
  worldPosition: THREE.Vector3
  input: InputIniModule
  extRender: any
  viewmodeData: ViewmodeData
  viewmode: number
  cameraData: CameraData
  renderer: ExtObjRender
  extObjViewData: ExtObjViewData
  constructor() {
    super(...arguments)
    this.name = "extobj-module"
  }
  async init(e, engine: EngineContext) {
    this.engine = engine
    const WebGLScene = (await engine.getModuleBySymbol<WebGLRendererModule>(SymbolList.WEBGL_RENDERER)).getScene()
    const input = await engine.getModuleBySymbol<InputIniModule>(SymbolList.INPUT)
    const [settings, cameraData, extObjViewData, viewmodeData] = await Promise.all([
      engine.market.waitForData(SettingsData),
      engine.market.waitForData(CameraData),
      engine.market.waitForData(ExtObjViewData),
      engine.market.waitForData(ViewmodeData)
    ])
    this.viewmodeData = viewmodeData
    this.viewmode = viewmodeData.currentMode
    this.extObjViewData = extObjViewData
    this.cameraData = cameraData
    this.renderer = new ExtObjRender(WebGLScene.scene, input, settings, extObjViewData, engine.claimRenderLayer(this.name), e.readOnly)
    engine.addComponent(this, this.renderer)
  }
  loadObjInfos(infos, readOnly = false) {
    const taskList = []
  }
}
